package com.bawei.module_home.discovery.adapter.provider

import android.content.Context
import android.graphics.Outline
import android.view.View
import android.view.ViewOutlineProvider
import android.widget.ImageView
import com.bawei.library_common.utils.ImageUtils
import com.bawei.module_home.R
import com.bawei.module_home.discovery.entity.DiscoveryEntity
import com.chad.library.adapter.base.provider.BaseItemProvider
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.youth.banner.Banner
import com.youth.banner.Transformer
import com.youth.banner.loader.ImageLoader

/**
 * @Author : yaotianxue
 * @Time : On 2023/5/29 19:30
 * @Description : TopBannerProvider
 */
class TopBannerProvider(override val itemViewType: Int, override val layoutId: Int) :BaseItemProvider<DiscoveryEntity.Item>() {
    override fun convert(helper: BaseViewHolder, item: DiscoveryEntity.Item) {
        var banner = helper.getView<Banner>(R.id.banner)//view
        var bannerList = item.data.itemList//数据
        //为轮播图设置数据
        banner.setImages(bannerList)
        banner.setImageLoader(object :ImageLoader(){
            override fun displayImage(context: Context, path: Any, imageView: ImageView) {
                var itemX = path as DiscoveryEntity.ItemX
                ImageUtils.loadImageView(context,itemX.data.image,imageView)
            }
        })
        banner.setBannerAnimation(Transformer.CubeIn)//动画
        banner.outlineProvider = object : ViewOutlineProvider(){//轮廓
            override fun getOutline(view: View, outline: Outline) {
                outline.setRoundRect(0,0,view.width,view.height,30f)
            }

        }
        banner.start()
    }
}